home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / PowerBook / PB180c Screen Tester ƒ / pbst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  4.3 KB  |  225 lines  |  [TEXT/ttxt]

  1. /****************************************************/
  2. /* Powerbook Screen Tester                            */
  3. /*                                                    */
  4. /* Initial Version - 6/10/93                        */
  5. /*                                                    */
  6. /* Author: David M. Meleedy                         */
  7. /*             dmm@head-cfa.harvard.edu                */
  8. /****************************************************/
  9.  
  10. #include <AppleEvents.h>
  11. #include <Values.h>
  12.  
  13. #define        kMoveToFront        (WindowPtr)-1L
  14. #define        kEmptyString        "\p"
  15. #define        kEmptyTitle            kEmptyString
  16. #define        kVisible            true
  17. #define        kNoGoAway            false
  18. #define        kNilRefCon            (long) nil
  19. #define        kSleep                MAXLONG
  20. #define        kHorizontalPixel    30
  21. #define        kVerticalPixel        50
  22. #define        kTextSize            20
  23.  
  24. /***********************/
  25. /*  GLOBALS            */
  26. /***********************/
  27.  
  28. short    gOldMBarHeight;
  29. Boolean    gDone;
  30.  
  31. /***********************/
  32. /*** FUNCTIONS           */
  33. /***********************/
  34.  
  35. void    ToolBoxInit ( void );
  36. void    WindowInit    ( void );
  37. void    MainLoop    ( void );
  38. void    DoEvent        ( EventRecord *eventPtr );
  39. void    HandleKeyDown    ( EventRecord *eventPtr );
  40. void    HandleMouseDown    ( void );
  41. void    cycle_color ( void );
  42.  
  43. void    main ( void )
  44. {
  45.     ToolBoxInit ();
  46.     WindowInit ();
  47.     MainLoop ();
  48. }
  49.  
  50. void    MainLoop ( void )
  51. {
  52.  
  53.     EventRecord    event;
  54.     
  55.     gDone = false;
  56.     
  57.     while ( gDone == false )
  58.     {
  59.         if ( WaitNextEvent ( everyEvent, &event,
  60.             kSleep, nil ) )
  61.                 DoEvent ( &event );
  62.     }
  63.     
  64.     MBarHeight = gOldMBarHeight;
  65.     ShowCursor();
  66. }
  67.  
  68. void    DoEvent ( EventRecord *eventPtr )
  69. {
  70.     switch ( eventPtr->what )
  71.     {
  72.         case mouseDown:
  73.             HandleMouseDown();
  74.             break;
  75.         case autoKey:
  76.         case keyDown:
  77.             HandleKeyDown( eventPtr );
  78.             break;
  79.     }
  80. }
  81.  
  82. void    HandleKeyDown ( EventRecord *eventPtr )
  83. {
  84.     WindowPtr        window;
  85.     Rect            windowRect;
  86.     char            thechar;
  87.  
  88.     thechar = eventPtr->message & charCodeMask;
  89.     
  90.     window = FrontWindow();
  91.     
  92.     windowRect.left = window->portRect.left;
  93.     windowRect.right = window->portRect.right;
  94.     windowRect.top = window->portRect.top;
  95.     windowRect.bottom = window->portRect.bottom;
  96.     
  97.     switch ( thechar )
  98.     {
  99.             case 'r':
  100.             case 'R':
  101.                     ForeColor ( redColor );
  102.                     break;
  103.             case 'g':
  104.             case 'G':
  105.                     ForeColor ( greenColor );
  106.                     break;
  107.             case 'b':
  108.             case 'B':
  109.                     ForeColor ( blueColor );
  110.                     break;
  111.             case 'w':
  112.             case 'W':
  113.                     ForeColor ( whiteColor );
  114.                     break;
  115.             case ' ':
  116.                     ForeColor ( blackColor );
  117.                     break;
  118.             case 'q':
  119.             case 'Q':
  120.                     gDone = true;
  121.                     break;
  122.             case '\r':
  123.                     cycle_color ();
  124.                     break;
  125.             default:
  126.                     break;
  127.     }
  128.     PaintRect ( &windowRect );    
  129. }
  130.  
  131. void    HandleMouseDown ( void )
  132. {
  133.     
  134.     gDone = true;
  135.     
  136. }
  137.  
  138. void    cycle_color ()
  139. {
  140.     static int    the_color = 1;
  141.     
  142.     if ( the_color == 6 )
  143.         the_color = 1;
  144.         
  145.     switch ( the_color )
  146.     {
  147.         case 1:
  148.             ForeColor ( blackColor );
  149.             break;
  150.         case 2:
  151.             ForeColor ( whiteColor );
  152.             break;
  153.         case 3:
  154.             ForeColor ( redColor );
  155.             break;
  156.         case 4:
  157.             ForeColor ( greenColor );
  158.             break;
  159.         case 5:
  160.             ForeColor ( blueColor );
  161.             break;
  162.     }
  163.     the_color++;
  164. }
  165.  
  166. void    ToolBoxInit ( void )
  167. {
  168.     InitGraf ( &thePort );
  169.     InitFonts ();
  170.     InitWindows ();
  171. /*    InitMenus ();
  172.     TEInit();
  173.     InitDialogs ( nil ); */
  174.     InitCursor();
  175. }
  176.  
  177. void    WindowInit ( void )
  178. {
  179.     Rect        totalRect, mBarRect;
  180.     RgnHandle    mBarRgn;
  181.     WindowPtr    window;
  182.     short        fontNum;
  183.     
  184.     gOldMBarHeight = MBarHeight;
  185.     MBarHeight = 0;
  186.     
  187.     HideCursor();
  188.     
  189.     window = NewWindow ( nil, &(screenBits.bounds),
  190.                 kEmptyTitle, kVisible, plainDBox, kMoveToFront,
  191.                 kNoGoAway, kNilRefCon );
  192.                 
  193.     SetRect ( &mBarRect, screenBits.bounds.left,
  194.                 screenBits.bounds.top,
  195.                 screenBits.bounds.right,
  196.                 screenBits.bounds.top+gOldMBarHeight );
  197.                 
  198.     mBarRgn = NewRgn();
  199.     RectRgn ( mBarRgn, &mBarRect );
  200.     UnionRgn ( window->visRgn, mBarRgn, window->visRgn );
  201.     DisposeRgn ( mBarRgn );
  202.     SetPort ( window );
  203.     FillRect ( &(window->portRect), white );
  204.     
  205.     GetFNum ("\pTimes", &fontNum );
  206.     
  207.     if ( fontNum != 0)
  208.         TextFont ( fontNum );
  209.         
  210.     TextSize ( kTextSize );
  211.         
  212.     MoveTo ( kHorizontalPixel, kVerticalPixel );
  213.     DrawString ("\pkeys:");
  214.     MoveTo ( kHorizontalPixel, kVerticalPixel + (kTextSize * 2) + 2 );
  215.     DrawString ("\p<r> red, <g> green, <b> blue");
  216.     MoveTo ( kHorizontalPixel, kVerticalPixel + (kTextSize * 3) + 2 );
  217.     DrawString ("\p<w> white, <space> black");
  218.     MoveTo ( kHorizontalPixel, kVerticalPixel + (kTextSize * 5) + 2 );
  219.     DrawString ("\p<return> cycle through colors");    
  220.     MoveTo ( kHorizontalPixel, kVerticalPixel + (kTextSize * 7) + 2);
  221.     DrawString ("\p<q> or [mouse_click] quit");
  222.     MoveTo ( kHorizontalPixel, kVerticalPixel + (kTextSize * 11) + 2);
  223.     DrawString ("\pWritten by David M. Meleedy.");
  224. }
  225.